const mysql = require("mysql");

let pool = mysql.createPool({
  host: 'localhost',
  port: 3306,
  user: 'root',
  password: 'root',
  database: 'yuekan',
  insecureAuth:true
})

function getCon() {
  return new Promise((resolve, reject) => {
    pool.getConnection((err, con) => {
      if (err) {
        reject(err)
      } else {
        resolve(con)
      }
    })
  })
}
async function sqlQuery(sql, pms) {
  let con = await getCon()
  return new Promise((resolve, reject) => {
    con.query(sql, pms, (err, data) => {
      if (err) {
        reject(err)
      } else {
        resolve(data)
        con.release()
      }
    })
  })
}
module.exports = sqlQuery